package com.feishi.project.broker.init;

import com.feishi.core.analytic.assembler.DefaultAssembler;
import com.feishi.core.socket.common.SocketDecoder;
import com.feishi.core.socket.common.decoder.NoneDecoder;
import com.feishi.core.socket.common.lifecycle.SocketSession;
import com.feishi.core.socket.netty.ChannelHandlerFactory;
import com.feishi.core.socket.netty.NettyServer;
import com.feishi.core.socket.netty.handler.NettyHandler;
import com.feishi.core.util.common.ByteUtil;
import com.feishi.core.util.common.bean.ByteBufferProxy;
import com.feishi.project.broker.filter.BrokerFilter;
import io.netty.channel.ChannelHandler;
import lombok.Data;
import lombok.extern.log4j.Log4j;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: caixq
 * Date: 2018-12-24
 * Time: 下午1:49
 */
@Component
@Data
@Slf4j
public class Init {

    @Value("${server.port}")
    private int serverPort;
    @Autowired
    private BrokerFilter brokerFilter;

    @PostConstruct
    public void init() {
        NettyServer<DefaultAssembler> server = new NettyServer() {
            @Override
            public int getPort() {
                return serverPort;
            }
        };
        server.setDecoder(new NoneDecoder<>());
        server.getApplication().addFilter(brokerFilter);


        server.startServer();
    }

    public static void main(String[] args) {

    }
}
